<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ include file="/include/taglib.jsp" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>我的账户-短信确认</title>
    <jsp:include page="/include/wchat/head.jsp"></jsp:include>

    <link type="text/css" rel="stylesheet"
          href="/v2/wchat/resrc/css/account.css">
</head>
<style>
    .surePw .login_input {
        margin-top: 10px;
    }

    .change-passwd {
        padding: 30px 10px 0;
    }

    .input-box {
        padding: 0;
        width: 100%;
    }

    .login_input {
        margin-top: 0;
        float: left;
    }

    .mdfPw {
        float: left;
        margin-bottom: 20px;
        width: 100%;
    }

    .mdfPw .in_put {
        padding: 5px 10px;
    }

    .r_line {
        line-height: 26px;
        text-align: center;
    }

    .link-touch {
        border: none;
        position: static;
    }

    .link-touch .txt {
        float: none;
        width: 100%;
    }

    .link-touch .errs {
        padding: 10px 0 0;
        clear: both
    }
</style>

<body>
<div id="header">
    <a href="javascript:history.go(-1);" class="backto">返回</a>
    <div class="title-sub">短信确认</div>
</div>
<div id="wrap">
    <form action="/allinPayIsBindBankCard.do" method="POST"
          id="allinPayIsBindBankCard">
        <input id="SRCREQ_SN" name="SRCREQ_SN" type="hidden" value="${SRCREQ_SN}">
        <div class="form_warp">
            <p class="tips_txt1 ng-binding">本次绑卡需要短信确认，校验码已发送至您手机${mobile}</p>
            <div class="link-touch mdfPw">
                <div class="input-box">
                    <div class="login_input">
                        <div class="r_line">
                            <label class="txt">校验码</label>
                        </div>
                        <div class="in_put">
                            <input placeholder="请输入校验码" id="captcha" name="captcha" value=""
                                   maxlength="6" onkeydown="if(event.keyCode==13){checkPassword();}"
                                   type="number">
                        </div>
                    </div>
                    <div class="getPW"><a id="getAutoPwdBtn" href="javascript:getAutoPwd();">获取校验码</a></div>
                </div>
            </div>
        </div>
        <div id="newPwdErrorTip" class="errTips"></div>
        <div class="Nxt-btn">
            <a href="javascript:allinPayIsBindBankCard();">下一步</a>
        </div>
    </form>

    <jsp:include page="/include/wchat/footer.jsp"></jsp:include>

    <script type="text/javascript">

        function allinPayIsBindBankCard() {
            var verCode = $("#captcha").val();
            var SRCREQ_SN = $("#SRCREQ_SN").val();
            if (verCode == "" || verCode == null) {
                $("#newPwdErrorTip").html("请输入校验码").show();
                return;
            }
            if($("#getAutoPwdBtn").hasClass("disable-bt")){
                return;
            }
            var param = {};
            param["paramMap.SRCREQ_SN"] = SRCREQ_SN;
            param["paramMap.verCode"] = verCode;
            $.ajax({
                type: 'POST',
                url: "/allinPaySmsCodeCheck.do",
                data: param,
                success: function(data) {
                    if(data.errCode == "success"){
                        window.location.href = data.checkUrl;
                    }else if(data.errCode == 1001){
                        $("#newPwdErrorTip").html("请求失败，请稍后再试！").show();
                        return;
                    }else if(data.errCode == 3998){
                        $("#newPwdErrorTip").html("验证码错误，请重新输入！").show();
                        return;
                    }else{
                        $("#newPwdErrorTip").html(data.msg).show();
                        return;
                    }
                }
            });
        }

        function getAutoPwd() {
            var vCode = $("#authCode").val();
            if (vCode == "" || vCode == null) {
                $("#newPwdErrorTip").html("请输入验证码").show();
                return;
            }
            if($("#getAutoPwdBtn").hasClass("disable-bt")){
                return;
            }
            $("#pWord").removeClass().addClass("icon-pWord2");
            var param = {};
            param["paramMap.pageId"] = "modifyPayPwd";
            param["paramMap.mobile"] = $("#mobile").val();
            param["paramMap.authCode"] = $("#authCode").val();
            $.ajax({
                type: 'POST',
                url: "/getAutoPwd.do",
                data: param,
                success: function(data) {
                    //错误等信息提示
                    if(data.code == "failed"){
                        $("#newPwdErrorTip").html(data.msg).show();
                        return;
                    }
                    if(data.code == "errorCode"){
                        $("#newPwdErrorTip").html(data.msg).show();
                        switchCode('modifyPayPwd');
                        return;
                    }
                    //倒计时
                    _interval = setInterval("autoPwdSend()", 1000);
                }
            });
        }

        /**
         * 60秒计时
         */
        var n = 60;
        /**
         * 连续执行方法句柄
         */
        var _interval;
        /**
         * 发送动态密码循环执行方法
         */
        function autoPwdSend(){
            n--;
            //获取验证码按钮 不可用
            $("#getAutoPwdBtn").addClass("disable-bt");
            $("#getAutoPwdBtn").attr("href","javascript:;").html(n + "秒后可重发");

            if (n == 0) {
                $("#getAutoPwdBtn").removeClass("disable-bt");
                $("#getAutoPwdBtn").attr("href","javascript:getAutoPwd();").html("获取动态码");
                clearInterval(_interval);
                n = 60;
            }
        }
    </script>
</body>
</html>